import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
import 'package:flutter/rendering.dart';

void main() {
  runApp(
    MaterialApp(
      theme: ThemeData(primarySwatch: Colors.red), // FIXME 没生效
      home: Scaffold(
        appBar: AppBar(title: const Text('你好flutter12')),
        body: const Wrap(
          children: [
            ImageWidget(),
            MyApp(),
            SizedBox(width: 20), // 宽度高度组件
            CircuiarImg(),
            SizedBox(width: 20),
            ClipImg(),
            SizedBox(width: 20),
            CircleAvatarImg(),
            SizedBox(width: 20),
            LocalImg()
          ],
        ),
      ),
    ),
  );
}

// Image 组件
class ImageWidget extends StatelessWidget {
  const ImageWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return const Image(
      image: AssetImage('images/a.png'),
      // image: NetworkImage('https://cdn.uviewui.com/uview/album/1.jpg'),
      width: 100,
    );
  }
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Container(
        width: 150,
        height: 150,
        decoration: const BoxDecoration(color: Colors.teal),
        child: Image.network(
          'https://cdn.uviewui.com/uview/album/1.jpg',
          // scale: 4,
          // fit:BoxFit.fill,
          alignment: Alignment.bottomCenter,
          // repeat: ImageRepeat.repeatY,
        ),
      ),
    );
  }
}

// 圆形图片1 borderRadius
class CircuiarImg extends StatelessWidget {
  const CircuiarImg({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 150,
      height: 150,
      margin: const EdgeInsets.fromLTRB(0, 30, 0, 0),
      decoration: BoxDecoration(
        color: Colors.teal,
        borderRadius: BorderRadius.circular(75),
        image: const DecorationImage(
          image: NetworkImage('https://cdn.uviewui.com/uview/album/1.jpg'),
          fit: BoxFit.cover,
        ),
      ),
    );
  }
}

// 圆形图片2 ClipOval
class ClipImg extends StatelessWidget {
  const ClipImg({super.key});

  @override
  Widget build(BuildContext context) {
    return ClipOval(
      child: Image.network(
        'https://cdn.uviewui.com/uview/album/1.jpg',
        width: 150,
        height: 150,
        fit: BoxFit.cover,
      ),
    );
  }
}

// 圆形图片3 CircleAvatar
class CircleAvatarImg extends StatelessWidget {
  const CircleAvatarImg({super.key});

  @override
  Widget build(BuildContext context) {
    return const SizedBox(
      width: 150,
      height: 150,
      child: CircleAvatar(
        backgroundImage:
            NetworkImage('https://www.itying.com/images/flutter/2.png'),
      ),
    );
  }
}

// 加载本地图片 pubspec.yaml 配置文件 assets项
class LocalImg extends StatelessWidget {
  const LocalImg({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 150,
      width: 250,
      decoration: const BoxDecoration(
        color: Colors.red,
      ),
      child: Image.asset(
        'images/a.png',
        fit: BoxFit.contain,
      ),
    );
  }
}
